package com.sdgakj.interviews.job20180814;

import java.util.Arrays;

/**
 * @Author: Du Ronghong
 * @Description:
 * @Date: Created in 10:06 2018/8/15
 * @Modified By:
 */
public class InsertSortTest {

    public static void main(String[] args) {

        int[] num = {10, 2, 6, 3, 8, 1, 5};
        System.out.println(Arrays.toString(insertSort(num)));
    }


    private static int[] insertSort(int[] num) {
        if (num.length == 0) {
            return null;
        }
        int i = 0;
        do {
            int m = num[i];
            int j = i;
            if (j > 0 && num[j - 1] > m) {
                do {
                    num[j] = num[j - 1];
                    j--;
                } while (j > 0 && num[j - 1] > m);
            }
            num[j] = m;
            i++;
        } while (i < num.length);
        return num;
    }
}
